<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="java.sql.*"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>注册信息</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

</head>
<body>
	<%
		int i = 0;
		response.setCharacterEncoding("UTF-8");
		request.setCharacterEncoding("UTF-8");
		String act = request.getParameter("act");

		Connection conn = null;
		Statement stat = null;
		if(act == null || !act.equals("reg")) {
			i = 0;
		}else {
			String username = request.getParameter("username");
			String password0 = request.getParameter("password0");
			String email = request.getParameter("email");
			String question = request.getParameter("question");
			String answer = request.getParameter("answer");
	
			Class.forName("org.gjt.mm.mysql.Driver");
			String url = "jdbc:mysql://localhost:3306/db_onlinenote";
			String user = "root";
			String password = "admin";
			conn = DriverManager.getConnection(url, user, password);
			stat = conn.createStatement();
			String sql = "insert into user(username,psd,email,question,answer)values('" + username + "','" + password0 + "','" + email + "','" + question + "','" + answer + "')";
			i = stat.executeUpdate(sql);
		}
	%>

	<center>
		<%
			if (i != 0) {
				out.print("<br><h3>注册成功！</h3>");
			} else {
		%>
		<a href=register.jsp>输入错误，请重新注册</a>
		<%
			}
		%>

		<br> <a href=login.jsp>登陆</a>
	</center>
	<%
		if (stat != null) {
			stat.close();
		}
		if (conn != null) {
			conn.close();
		}
	%>
</body>
</html>
